opera.extension.onmessage = function (e) {
    // post to top level window
    if (e.data && e.data.indexOf('vanishing-click') == 0) {
	vanishingClick();
	}
}

function vanishingClick() {
	(function () {

		function addEvent(obj, type, fn) {
			if (obj.addEventListener) obj.addEventListener(type, fn, false);
			else if (obj.attachEvent) {
				obj["e" + type + fn] = fn;
				obj[type + fn] = function () {
					obj["e" + type + fn](window.event);
				}
				obj.attachEvent("on" + type, obj[type + fn]);
			}
		}

		function removeEvent(obj, type, fn) {
			if (obj.removeEventListener) obj.removeEventListener(type, fn, false);
			else if (obj.detachEvent) {
				obj.detachEvent("on" + type, obj[type + fn]);
				obj[type + fn] = null;
				obj["e" + type + fn] = null;
			}
		}
		
		var eventkeyDown = function (event) {
			var e = event || window.event
			var characterCode = e.which || e.keyCode;
			if (characterCode == 27){
				try {
					removeEvent(window, 'mouseover', eventMouseOver );
					removeEvent(window, 'mousedown', eventMouseDown );
					removeEvent(document, 'keydown', eventkeyDown );
				} catch (e) {}
			}
		};		

		var eventMouseOver = function (event) {
			highlight(event.target);
			addEvent(window, 'mousedown', eventMouseDown );
		};
		var eventMouseDown = function (event) {
			var element = event.target;
			element.parentNode.removeChild(element);
		};

		function highlight(element){
			var oriBgClr = element.style.backgroundColor;
			var oriBorder = element.style.border;
			element.style.backgroundColor='#ffe784';
			element.style.border='1px dashed #ff0000';
			
			addEvent(element, 'mouseout', function (e) {
				element.style.backgroundColor=oriBgClr;
				element.style.border=oriBorder;
			} );
		}
		
		addEvent(document, 'keydown', eventkeyDown );
		addEvent(window, 'mouseover', eventMouseOver );

	})();
}